package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.teaching.domain.vo.InsertTeachingPlan;
import com.ruoyi.teaching.domain.vo.PreviewTeachingPlan;
import com.ruoyi.teaching.domain.vo.RelatedInterviewVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.TeachingPlan;
import com.ruoyi.teaching.service.ITeachingPlanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 教学计划Controller
 *
 * @author sunshine
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/teaching_plan")
public class TeachingPlanController extends BaseController
{
    @Autowired
    private ITeachingPlanService teachingPlanService;

    /**
     * 查询教学计划列表
     */
    @RequiresPermissions("teaching:teaching_plan:list")
    @GetMapping("/list")
    public TableDataInfo list(TeachingPlan teachingPlan)
    {
        startPage();
        List<TeachingPlan> list = teachingPlanService.selectTeachingPlanList(teachingPlan);
        return getDataTable(list);
    }
    @RequiresPermissions("teaching:teaching_plan:list")
    @GetMapping("/listPlanByStudent")
    public AjaxResult listPlanByStudent(TeachingPlan teachingPlan)
    {
        RelatedInterviewVo list = teachingPlanService.selectTeachingPlanByStudentList(teachingPlan);
        return AjaxResult.success(list);
    }

    @RequiresPermissions("teaching:teaching_plan:add")
    @PostMapping("/preview")
    public AjaxResult previewTeachingPlan(@Valid PreviewTeachingPlan previewTeachingPlan)
    {
        return AjaxResult.success(teachingPlanService.previewTeachingPlanList(previewTeachingPlan));
    }
    @RequiresPermissions("teaching:teaching_plan:add")
    @PostMapping("/addWorkday")
    public AjaxResult addWorkday(@Valid PreviewTeachingPlan previewTeachingPlan)
    {
        teachingPlanService.addWorkday(previewTeachingPlan.getClassesId(),previewTeachingPlan.getDate());
        return AjaxResult.success(teachingPlanService.previewTeachingPlanList(previewTeachingPlan));
    }
    @RequiresPermissions("teaching:teaching_plan:add")
    @PostMapping("/addHoliday")
    public AjaxResult addHoliday(@Valid PreviewTeachingPlan previewTeachingPlan)
    {
        teachingPlanService.addHoliday(previewTeachingPlan.getClassesId(),previewTeachingPlan.getDate(),previewTeachingPlan.getType());
        return AjaxResult.success(teachingPlanService.previewTeachingPlanList(previewTeachingPlan));
    }

    /**
     * 导出教学计划列表
     */
    @RequiresPermissions("teaching:teaching_plan:export")
    @Log(title = "教学计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingPlan teachingPlan)
    {
        List<TeachingPlan> list = teachingPlanService.selectTeachingPlanList(teachingPlan);
        ExcelUtil<TeachingPlan> util = new ExcelUtil<TeachingPlan>(TeachingPlan.class);
        util.exportExcel(response, list, "教学计划数据");
    }

    /**
     * 获取教学计划详细信息
     */
    @RequiresPermissions("teaching:teaching_plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teachingPlanService.selectTeachingPlanById(id));
    }

    /**
     * 新增教学计划
     */
    @RequiresPermissions("teaching:teaching_plan:add")
    @Log(title = "教学计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsertTeachingPlan teachingPlanList)
    {
        return AjaxResult.success(teachingPlanService.insertTeachingPlan(teachingPlanList));
    }

    /**
     * 修改教学计划
     */
    @RequiresPermissions("teaching:teaching_plan:edit")
    @Log(title = "教学计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingPlan teachingPlan)
    {
        return toAjax(teachingPlanService.updateTeachingPlan(teachingPlan));
    }

    /**
     * 删除教学计划
     */
    @RequiresPermissions("teaching:teaching_plan:remove")
    @Log(title = "教学计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teachingPlanService.deleteTeachingPlanByIds(ids));
    }
}
